package com.qiyu.security.util;

import cn.hutool.crypto.digest.BCrypt;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * @author zww
 */
public abstract class EncryptUtil {
    
    private static final String SALT = "DX_ACTIVITY";
    
    public static String encode(String password) {
        return BCrypt.hashpw(password, BCrypt.gensalt());
    }
    
    public static boolean matches(String source, String encrypt) {
        return BCrypt.checkpw(source, encrypt);
    }
    
    public static String hashEncode(String password) {
        return new Md5Hash(password, SALT, 10).toBase64();
    }
    
    public static boolean hashMatches(String source, String encrypt) {
        return Md5Hash.fromBase64String(encrypt).equals(new Md5Hash(source, SALT, 10));
    }
    
    public static void main(String[] args) {
        System.out.println(encode("root"));
    }
}
